require.config({
	paths : {
		"jquery" : "jquery",
		"common":"xz-common",
		"cookie":"jquery.cookie"
	}
})
$pot=1;
require(["common","jquery","cookie"],function(common,$){
		$(function(){
		//是否登录
        if($.cookie("login")){
        	$("#xz-login").text($.cookie("login")+" ，点击重新登录");
        }else{
        	$("#xz-login").text("【登录】");
        }
     //退出
      $("#xz-login").mousedown(function(){
      	$.removeCookie("login",{expires:0,path:"/"});
      	location.href = "../html/login.html";
      })
	})
	$(function(){	
     var str1 =converStrToObj($.cookie("user")) ;
    
    
    //对象转字符串
    function converObjToStr(obj){
    	var str = "";
    	for(var user in obj){
    		var pwd = obj[user]; 
    		if(str){
    			str +=":";
    		}
    		str += user +","+pwd;
    	}
    	return str;
    }
    
   //字符串转对象
	function converStrToObj(str){
		if(!str){
		return{};	
		}
		var arr = str.split(":");
		var obj={};
		for(var i= 0;i<arr.length;i++){
			var arr1 = arr[i].split(",");
			obj[arr1[0]] = arr1[1];
		}
		
		return obj;
	}
	
	
		
		
	//边框滑过
	$( ".xz-register-in1").each(function(i){
		$(".xz-register-in1").eq(i).hover(function(){
		$(".xz-register-in1").eq(i).css({
    		"box-shadow":"0 0 20px #ea5d8e " ,
    		"border":"1px solid red"
    	})
	},function(){
		$(".xz-register-in1").eq(i).css({
    		"box-shadow":"0 0 0px #ea5d8e ",
          })
	   })
	})
	
	$( ".xz-register-in2").each(function(i){
		$(".xz-register-in2").eq(i).hover(function(){
		$(".xz-register-in2").eq(i).css({
    		"box-shadow":"0 0 20px #ea5d8e " ,
    		"border":"1px solid red"
    	})
	},function(){
		$(".xz-register-in2").eq(i).css({
    		"box-shadow":"0 0 0px #ea5d8e ",
    	})
	})
	})
	
	
	//手机号
	$sign=false;//全部提示错误信息消失
	$("#xz-register-phonenumber").mouseleave(function(){
    if(/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/.test($("#xz-register-phonenumber").val())
	){
		
		$(".xz-correct").eq(0).css({"display":"block"});
		$("#xz-phoneerror").css({"display":"none"});
		$("#xz-register-phonenumber").eq(0).css({
    		"border":"1px solid #e1e1e1"	
    	})
		$sign=true;
		if( $("#xz-register-phonenumber").val()  in str1){
		$("#xz-phoneerror").css({"display":"block"});
		$("#xz-phoneerror").text("手机号已经注册");
		$(".xz-correct").eq(0).css({"display":"none"});
	}
	}
	else{
		$("#xz-phoneerror").css({"display":"block"});
		$(".xz-correct").eq(0).css({"display":"none"});
		$sign=false;
	}
   })
	//验证码

	function randomnum(){
		var str="";
		var strsource=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
        for(var i=0;i<4;i++){
        var n=Math.floor(Math.random()*strsource.length);
        str=str+strsource[n];
        
	}
   return str;
	}
		$sign1=false;
	$(function(){
		$(".VerificationCode").html(randomnum());
		$(".VerificationCode").mousedown(function(){
			$(".VerificationCode").html(randomnum());
		})
		
	$("#xz-register-random").mouseleave(function(){
	
    if($("#xz-register-random").val()==$(".VerificationCode").html())
	{
		$(".xz-correct").eq(1).css({"display":"block"});
		$("#xz-randomerror").css({"display":"none"});
		$(".xz-register-in2").eq(0).css({
    		"border":"1px solid #e1e1e1"
    	})
		$sign1=true;
	}else{
		$("#xz-randomerror").css({"display":"block"});
		$(".xz-correct").eq(1).css({"display":"none"});
		$sign1=false;
	}
    })
//手机验证码		
		$sign2=false;
	$("#xz-register-phonerandom").mouseleave(function(){
    if($("#xz-register-phonerandom").val()=="")
	{		
		$("#xz-phonerandom").css({"display":"block"});
         $sign2=false;
	}else{
		$("#xz-phonerandom").css({"display":"none"});
		$(".xz-register-in2").eq(1).css({
    		"border":"1px solid #e1e1e1"
    	})
		$sign2=true;
	}
    })	
		
	$sign3=false;	
//设置密码		
	$("#xz-register-password").mouseleave(function(){
    if(/^[a-zA-Z]\w{5,17}$/.test($("#xz-register-password").val())){

		$("#xz-password").css({"display":"none"});
		$(".xz-register-in1").eq(1).css({
    		"border":"1px solid #e1e1e1"
    	})
		$sign3=true;
	}else{
		$("#xz-password").css({"display":"block"});
		$("#xz-password").text("必须是以数字开头的数字字母下滑下组成");
		$sign3=false;
	}
    })		
//重复密码
    $sign4=false;
		$("#xz-register-password1").mouseleave(function(){
    if($("#xz-register-password").val()==$("#xz-register-password1").val() ){
		$("#xz-password1").css({"display":"none"});
		$(".xz-register-in1").eq(2).css({
    		"border":"1px solid #e1e1e1"
    	})
		$sign4=true;
	}else{
		
		$("#xz-password1").css({"display":"block"});
		$sign4=false;
	}
    })	
	
	
	
		
	})
//重复密码
   
//提交注册信息
 $(".xz-register-put").mousedown(function(){
 if($sign&&$sign1&&$sign2&&$sign3&&$sign4){
  str1[$("#xz-register-phonenumber").val()]=$("#xz-register-password").val(); 
  str2 = converObjToStr(str1);
  $.cookie("user",str2,{expires:7,path:"/"});
  location.href="../html/login.html";
 }


 })

 
 
	

	})
	$(function(){
	     //购物车跳转
    $("#xz-shopcar").mousedown(function(){
    	location.href = "../html/shopcar.html"
    	
    });
    //注册页跳转
    $("#toresgister").mousedown(function(){
    	location.href = "../html/register.html"
    
    });    
    //登录页跳转
     $("#xz-login").mousedown(function(){
    	location.href = "../html/login.html"
    	
    })		
    //列表页跳转
     $(".xz-listofgoods-one a").mousedown(function(){
     	location.href = "../html/listgoods.html"
     	
     })
	})
})
